Skip to content

fix: handle TypeError exposed by simple history logic#5476

Merged
matthewelwell merged 2 commits intomainfrom
fix/handle-typeerror-in-simple-history
May 29, 2025
Merged

fix: handle TypeError exposed by simple history logic#5476
matthewelwell merged 2 commits intomainfrom
fix/handle-typeerror-in-simple-history

Conversation

@matthewelwell
Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Fixes this Sentry issue.

How did you test this code?

Existing tests cover the lack of regression, this change is purely to handle a scenario that is not possible to rerproduce but has been seen in production as per linked sentry issue.

@matthewelwell matthewelwell requested a review from a team as a code owner May 21, 2025 11:19
@matthewelwell matthewelwell requested review from gagantrivedi and removed request for a team May 21, 2025 11:19
@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview May 22, 2025 10:26am
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview May 22, 2025 10:26am
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview May 22, 2025 10:26am

@github-actions github-actions Bot added api Issue related to the REST API fix labels May 21, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-5476 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-5476 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-5476 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-5476 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-5476 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5476 Finished ✅ Results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2025

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/5476

⚙️ Updating now by workflow run 15184201650.

What is Uffizzi? Learn more!

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.65%. Comparing base (a0e7c5b) to head (ba588c1).
Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5476      +/-   ##
==========================================
- Coverage   97.65%   97.65%   -0.01%     
==========================================
  Files        1235     1235              
  Lines       43334    43333       -1     
==========================================
- Hits        42317    42316       -1     
  Misses       1017     1017              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added fix and removed fix labels May 22, 2025
Copy link
Copy Markdown
Contributor

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with minor comment

Comment thread api/core/models.py

def get_change_details(self) -> typing.Optional[typing.List[ModelChange]]: # type: ignore[return]
if self.history_type == "~": # type: ignore[attr-defined]
def get_change_details(self) -> typing.List[ModelChange]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case we could add a test to ensure it's covered

def test_get_change_details_handles_exception_prev_record_is_null():
    instance = HistoricalFeatureState(history_type="~")
    instance.prev_record = None 

    assert instance.get_change_details() == []

Ideally we could log when it happens but I let you decide if we will really track it or covering the case is enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it's not that easy. prev_record is a property, not an attribute, so I think any test that we add would involve more mocking than is really worthwhile.

Regarding the logging, since we've only seen this on a handful of cases, and the use case for this data is pretty slim, I don't think it's worth investigating further, hence negating the need for any additional logging.

I'm going to go ahead and merge this, but let me know if you disagree with either of my points above.

@matthewelwell matthewelwell merged commit 3d4d43e into main May 29, 2025
32 checks passed
@matthewelwell matthewelwell deleted the fix/handle-typeerror-in-simple-history branch May 29, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants